package com.dks.repository.impl;

import java.util.*;

import com.dks.dto.InvitationRecordDto;
import com.dks.dto.RewardDto;
import com.dks.mapper.InvitationRecordMapper;
import com.dks.models.InvitationRecord;
import com.dks.repository.IInvitationRecordRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;
import com.dks.util.PageInfo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class InvitationRecordRepository implements IInvitationRecordRepository {

    private InvitationRecordMapper invitationRecordMapper;

    @Autowired
    public InvitationRecordRepository(final InvitationRecordMapper invitationRecordMapperIn) {
        this.invitationRecordMapper = invitationRecordMapperIn;
    }

    @Override
    public Integer insert(InvitationRecord invitationRecord){
        return invitationRecordMapper.insert(invitationRecord);
    }

    @Override
    public Integer update(InvitationRecord invitationRecord){
        return invitationRecordMapper.update(invitationRecord);
    }

    @Override
    public Integer delete(Integer id){
        return invitationRecordMapper.delete(id);
    }

    @Override
    public InvitationRecord select(Integer id){
        return invitationRecordMapper.select(id);
    }

    @Override
    public Integer cntByMap(Map<String,Object> map){
        return invitationRecordMapper.cntByMap(map);
    }

    @Override
    public List<Integer> getByMap(Map<String,Object> map){
        return invitationRecordMapper.getByMap(map);
    }

    @Override
    public List<InvitationRecordDto> getByMapList(Map<String,Object> map){
        return invitationRecordMapper.getByMapList(map);
    }

    @Override
    public Integer updateByCode(InvitationRecord invitationRecord){
        return invitationRecordMapper.updateByCode(invitationRecord);
    }

    @Override
    public InvitationRecord selectByBfCode(String bfCode){
        return invitationRecordMapper.selectByBfCode(bfCode);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取邀请记录列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: invitedUsersId 邀请人id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @Override
    public ResultModel<Object> getInvitationRewardList(Integer invitedUsersId, Integer pageNum, Integer pageSize) {
        Map<String,Object> map = new HashMap<>();
        map.put("invitedUsersId",invitedUsersId);
        map.put("recStatus",0);
        Page p = PageHelper.startPage(pageNum, pageSize);
        List<InvitationRecordDto> invitationRecordDtoList = invitationRecordMapper.getByMapList(map);
        PageInfo<InvitationRecordDto> pageInfo = new PageInfo<>(pageNum, pageSize, p.getTotal(), p.getPages(), invitationRecordDtoList);
        return Result.makeResult(ResultInfo.SUCCESS, pageInfo);

    }
}
